﻿using Microsoft.AspNetCore.Mvc;
using WMS.FC.Application.WCS.Interface;
using WMS.FC.Domain.DataTransferObject.WCS;
using WMS.FC.Infrastructure.Filter;

namespace WMS.FC.WebApi.Controllers
{
    /// <summary>
    /// 物流控制器
    /// </summary>
    public class WCSController : BaseConroller
    {
        /// <summary>
        /// 物流服务
        /// </summary>
        protected readonly IWcsService wcsService;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="wcsService"></param>
        public WCSController(IWcsService wcsService)
        {
            this.wcsService = wcsService;
        }

        /// <summary>
        /// 获取托盘信息
        /// </summary>
        /// <param name="dTO"></param>
        /// <returns></returns>
        [HttpPost]
        [TypeFilter(typeof(WCSFilter))]
        public async Task<IActionResult> GetTrayInfo(GetTrayInfoDTO dTO)
        {
            var response = await wcsService.GetTrayInfo(dTO);
            return Ok(response);
        }

        /// <summary>
        /// 获取托盘目标站台
        /// </summary>
        /// <param name="dTO"></param>
        /// <returns></returns>
        [HttpPost]
        [TypeFilter(typeof(WCSFilter))]
        public async Task<IActionResult> GetTrayTargetStation(GetTrayTargetStationDTO dTO)
        {
            var response = await wcsService.GetTrayTargetStation(dTO);
            return Ok(response);
        }

        /// <summary>
        /// 托盘入库
        /// </summary>
        /// <param name="dTO"></param>
        /// <returns></returns>
        [HttpPost]
        [TypeFilter(typeof(WCSFilter))]
        public async Task<IActionResult> PutTrayInbound(PutTrayInboundDTO dTO)
        {
            var response = await wcsService.PutTrayInbound(dTO);
            return Ok(response);
        }

        /// <summary>
        /// 呼叫空托盘出库
        /// </summary>
        /// <param name="dTO"></param>
        /// <returns></returns>
        [HttpPost]
        [TypeFilter(typeof(WCSFilter))]
        public async Task<IActionResult> GetEmptyTrayOutbound(GetEmptyTrayOutboundDTO dTO)
        {
            var response = await wcsService.GetEmptyTrayOutbound(dTO);
            return Ok(response);
        }

        /// <summary>
        /// 修改任务状态
        /// </summary>
        /// <param name="dTO"></param>
        /// <returns></returns>
        [HttpPost]
        [TypeFilter(typeof(WCSFilter))]
        public async Task<IActionResult> ChangeTaskState(ChangeTaskStateDTO dTO)
        {
            var response = await wcsService.ChangeTaskState(dTO);
            return Ok(response);
        }

        /// <summary>
        /// 堆垛机状态上报
        /// </summary>
        /// <param name="dTO"></param>
        /// <returns></returns>
        [HttpPost]
        [TypeFilter(typeof(WCSFilter))]
        public async Task<IActionResult> ChangeEquipmentState(ChangeEquipmentStateDTO dTO)
        {
            var response = await wcsService.ChangeEquipmentState(dTO);
            return Ok(response);
        }

        /// <summary>
        /// 托盘和电池绑定
        /// </summary>
        /// <param name="dTO"></param>
        /// <returns></returns>
        [HttpPost]
        [TypeFilter(typeof(WCSFilter))]
        public async Task<IActionResult> BindCell(BindCellDTO dTO)
        {
            var response = await wcsService.BindCell(dTO);
            return Ok(response);
        }

        /// <summary>
        /// 托盘和电池解绑
        /// </summary>
        /// <param name="dTO"></param>
        /// <returns></returns>
        [HttpPost]
        [TypeFilter(typeof(WCSFilter))]
        public async Task<IActionResult> UnbindCell(UnbindCellDTO dTO)
        {
            var response = await wcsService.UnbindCell(dTO);
            return Ok(response);
        }
    }
}
